<?php
require_once 'dao/ObserverUpdateObjectDAO.php';
require_once 'dao/ObserverUpdateDataDAO.php';

class PollObservingService extends AbstractService{
	private $observerUpdateObjectDAO;
	private $observerUpdateDataDAO;
	
	public function doService($requestId, $params){
		return null;
	}
	
	public function getObservingResponses($clientId, $params){

		$this->observerUpdateObjectDAO = new ObserverUpdateObjectDAO();
		$updateObjectList = $this->observerUpdateObjectDAO->selectObserverUpdateObjectList($clientId);
		
		$this->observerUpdateDataDAO = new ObserverUpdateDataDAO();
		if ($updateObjectList != null){
			$responseList = array();
			foreach ($updateObjectList as $updateObject){
				array_push($responseList, $this->getObserverUpdateData($updateObject["OBSERVER_UPDATE_DATA_ID"]));
				$this->observerUpdateObjectDAO->updateObserverUpdateObjectUpdateYn($clientId, $updateObject["OBSERVER_UPDATE_DATA_ID"], "Y");
			}
			return $responseList;
		}
		else
			return null;		
	}
	
	private function getObserverUpdateData($observerUpdateDataId){
		$data = $this->observerUpdateDataDAO->selectObserverUpdateData($observerUpdateDataId);
		$response = array();
		$response["serviceId"] = $data["SERVICE_ID"]."Observe";
		$response["requestId"] = $data["REQUEST_ID"];
		$response["returnCode"] = "0000";
		$response["returnMsg"] = "";
		$response["params"] = json_decode($data["PARAMS_JSON"], true);
		Logger::debug($response["params"]);
		return $response;
	}
}
?>